Skip to content

[dxgi] Add DXVK_HOTPATCHABLE to swapchain dispatcher (Round #2) - #6049

Merged
doitsujin merged 1 commit into
doitsujin:masterfrom
Sonicadvance1:2
Nov 16, 2026
Merged

doitsujin merged 1 commit into
doitsujin:masterfrom
Sonicadvance1:2

Conversation

@Sonicadvance1

Copy link
Copy Markdown
Contributor

DreamWorks Shrek 2 Remastered hooks a bunch of these functions for whatever reason. Mark them all as hotpatchable so the game works on arm64ec proton.

Turns out the reason why this was causing Deadlock to crash is that gcc-mingw has a bug with the ms_hook_prologue attribute on vtable entries. These entries end up getting offset 32 bytes forward for whatever reason. llvm-mingw and MSVC doesn't have this problem.

For now add a new hotpatchable attribute type which only triggers on arm64ec/chpe platforms. I confirmed this change works with Deadlock on x86 by virtue of being a nop there, and Shrek 2 Remastered also still works on my ARM desktop.

Might be worth contemplating switching over to llvm-mingw entirely.

[DreamWorks Shrek 2 Remastered](https://store.steampowered.com/app/2523740/DreamWorks_Shrek_2_Remastered/)
hooks a bunch of these functions for whatever reason.
Mark them all as hotpatchable so the game works on arm64ec proton.

Turns out the reason why this was causing Deadlock to crash is that
gcc-mingw has a bug with the `ms_hook_prologue` attribute on vtable
entries. These entries end up getting offset 32 bytes forward for
whatever reason. llvm-mingw and MSVC doesn't have this problem.

For now add a new hotpatchable attribute type which only triggers on
arm64ec/chpe platforms. I confirmed this change works with Deadlock on
x86 by virtue of being a nop there, and Shrek 2 Remastered also still
works on my ARM desktop.

Might be worth contemplating switching over to llvm-mingw entirely.
@doitsujin

Copy link
Copy Markdown
Owner

One think I don't quite understand is why this only breaks the swapchain stuff, we have hotpatchable code in e.g. the DXGI factory as well. Is it code size related in any way?

@Sonicadvance1

Sonicadvance1 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

One think I don't quite understand is why this only breaks the swapchain stuff, we have hotpatchable code in e.g. the DXGI factory as well. Is it code size related in any way?

Doesn't seem to be related.
I tried a little local test program that all it does is inherit from a base class with one variant being patchable and another one not and the vtable was just messed up on one.

#include <array>
#include <stdint.h>
#include <string.h>
#include <vector>
#include <cassert>

#if __has_attribute(ms_hook_prologue) && (defined(__i386__) || defined(__x86_64__))
#define DXVK_HOTPATCHABLE __attribute__((__ms_hook_prologue__))
#elif defined(DECLSPEC_CHPE_PATCHABLE)
#define DXVK_HOTPATCHABLE DECLSPEC_CHPE_PATCHABLE
#elif defined(__arm64ec__)
#define DXVK_HOTPATCHABLE __attribute__((hybrid_patchable))
#else
#define DXVK_HOTPATCHABLE
#endif

class GetBase {
    public:
    virtual void Entry_1() {}
    virtual uint32_t QueryInterface() = 0;
    virtual void Entry_3() {}
    protected:
    uint32_t GetBaseImage() { return 1; }
};

class Get_Unpatch : public GetBase {
    public:
    //DXVK_HOTPATCHABLE
    uint32_t QueryInterface() final {
        return GetBaseImage() + 1;
    }
};


class Get_Patch : public GetBase {
    public:
    DXVK_HOTPATCHABLE
    uint32_t QueryInterface() final {
        return GetBaseImage() + 2;
    }
};
GetBase* GetClassUnpatch() {
    return new Get_Unpatch;
}
GetBase* GetClassPatch() {
    return new Get_Patch;
}

Simple x86_64-w64-mingw32-g++ -O2 -shared a.cpp compile

Showing the two vtables:
Image_2026-11-16_14-36-16
Can see from the disassembly that the vtable entry for the patchable QueryInterface isn't pointing to the entrypoint it should be. It's actually 32 bytes forward from where it should be.

llvm-mingw doesn't have the problem.

@doitsujin

Copy link
Copy Markdown
Owner

fun... well, changing default compiler isn't really something I want to do right now (more something for another release cycle) since it'll need a huge amount of testing, not like we haven't had fun bugs that only surfaced with LLVM builds before, so I guess this workaround will do for now.

@doitsujin
doitsujin merged commit c6f453f into doitsujin:master Nov 16, 2026
4 checks passed
@Sonicadvance1
Sonicadvance1 deleted the 2 branch November 16, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants